<?php

namespace App\Console\Commands;

use App\Lib\Search;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;

class CommandDelEsAndRedis extends Command
{
    protected $signature = 'DelEsAndRedis';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '删除Es索引数据和redis缓存';

     /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // es索引集合
        $indexArr = [
            'chat_friend_anchor_user',//交友es
            'chat_friend_user',//交友es
            'kk_user',//用户信息
            'kk_room_none',//房间
            'kk_room_bussiness',//公会房间
            'kk_music',//音乐
            'kk_room_hot',//推荐房间
        ];

        //更新es
        $search = new Search();
        foreach($indexArr as $v){
            $search->deleteAllIndex($v);
            echo '删除ES索引成功-|'.$v." | \r\n";
        }

        // 删除redis缓存
        $keys = Redis::KEYS('*');
        // 删除所有匹配的键
        foreach ($keys as $key) {
            echo $key;
            echo "\r\n";
            Redis::DEL($key);
        }
        echo '删除redis缓存成功'."\r\n";

    }
}
